//
//  WDGoutRescueItemViewModel.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/10.
//

#import "WDGoutRescueItemViewModel.h"

@implementation WDGoutRescueItemViewModel
- (void)initialize
{
    [super initialize];
    
    _reqModel = [WDTaskRescuePageReqModel new];
    
    self.pageId = 1;
    self.pageSize = 15;
    _reqModel.size = self.pageSize;
    
    
    _alermReqModel = [WDSaveTaskAlarmReqModel new];
//    _alermReqModel.engineerId = [EDSAppDelegateTool sharedInstance].userInfoModel.id;
}

- (void)setupData {
    /*
    WDArrivalServiceItemModel *model = [WDArrivalServiceItemModel new];
    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
    model.plateNumber = @"鲁B325DE";
    model.vehicleVin = @"LFVBA14B3Y3014078";
    model.updateDatetime = @"2024-07-23 12:43:46";
    model.modelName = @"小型车";
    model.vehicleSalesValue = @"法系";
    model.taskNo = @"ABCDQWEQ";
    model.appointmentTime = @"2024-02-03 12:32";
    // 服务流程 0.待分派 1.待接车 2.检查中 3.维修中 4.待报单 5.已完成 6.已取消 7.已关闭
    model.servFlow = 0;
    [self.dataList addObject:model];
    
    model = [WDArrivalServiceItemModel new];
    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
    model.plateNumber = @"鲁B325DE";
    model.vehicleVin = @"LFVBA14B3Y3014078";
    model.updateDatetime = @"2024-07-23 12:43:46";
    model.modelName = @"小型车";
    model.vehicleSalesValue = @"法系";
    model.taskNo = @"ABCDQWEQ";
    model.appointmentTime = @"2024-02-03 12:32";
    // 服务流程 0.待分派 1.待接车 2.检查中 3.维修中 4.待报单 5.已完成 6.已取消 7.已关闭
    model.servFlow = 1;
    [self.dataList addObject:model];
    
    model = [WDArrivalServiceItemModel new];
    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
    model.plateNumber = @"鲁B325DE";
    model.vehicleVin = @"LFVBA14B3Y3014078";
    model.updateDatetime = @"2024-07-23 12:43:46";
    model.modelName = @"小型车";
    model.vehicleSalesValue = @"法系";
    model.taskNo = @"ABCDQWEQ";
    model.appointmentTime = @"2024-02-03 12:32";
    model.servFlow = 2;
    [self.dataList addObject:model];
    
    model = [WDArrivalServiceItemModel new];
    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
    model.plateNumber = @"鲁B325DE";
    model.vehicleVin = @"LFVBA14B3Y3014078";
    model.updateDatetime = @"2024-07-23 12:43:46";
    model.modelName = @"小型车";
    model.vehicleSalesValue = @"法系";
    model.taskNo = @"ABCDQWEQ";
    model.appointmentTime = @"2024-02-03 12:32";
    model.servFlow = 3;
    [self.dataList addObject:model];
    
    model = [WDArrivalServiceItemModel new];
    model.imgPath = @"https://youjia-image.cdn.bcebos.com/modelImage/3eaa1c34bae2808435e95131cd59bcc7/16957217327781266694.jpg@!1200_width";
    model.plateNumber = @"鲁B325DE";
    model.vehicleVin = @"LFVBA14B3Y3014078";
    model.updateDatetime = @"2024-07-23 12:43:46";
    model.modelName = @"小型车";
    model.vehicleSalesValue = @"法系";
    model.taskNo = @"ABCDQWEQ";
    model.appointmentTime = @"2024-02-03 12:32";
    model.servFlow = 4;
    [self.dataList addObject:model];
    [self.dataList addObject:model];
    [self.dataList addObject:model];
    */
}


/// 外出救援 工单管理列表分页
/// - Parameter completion: completion description
- (void)requestWithTaskRescue:(RequestCompletionBlock)completion {
    _reqModel.current = self.pageId;
    _reqModel.stationId = @([EDSAppDelegateTool sharedInstance].userInfoModel.stationId);
    if (self.reqModel.servFlow == 0) { // 待抢单
        _reqModel.engineerId = nil;
    } else { // 其他
        _reqModel.engineerId = @([EDSAppDelegateTool sharedInstance].userInfoModel.id);
    }
    
    @weakify(self);
    WDTaskRescuePageRequest *request = [[WDTaskRescuePageRequest alloc] initWithModel:self.reqModel];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            if (self.pageId == 1) {
                [self.dataList  removeAllObjects];
            }
            NSArray *list = respond.data;
            [self.dataList addObjectsFromArray:list];
//            [self.dataList addObjectsFromArray:list];
//            [self.dataList addObjectsFromArray:list];
            if (list && list.count > 0) {
                self.pageId += 1;
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

/// 获取服务站信息
/// - Parameter completion: completion description
- (void)requestWithServiceStationInfo:(RequestCompletionBlock)completion {
    @weakify(self);
    NSNumber *stationId = @([EDSAppDelegateTool sharedInstance].userInfoModel.stationId);
    WDServiceStationsRequest *request = [[WDServiceStationsRequest alloc] initWithStationId:stationId];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            self.serviceStationInfoModel = respond.data;
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
